const { Sequelize } = require("sequelize");
const {
  DB_HOST,
  DB_DBS,
  DB_USERNAME,
  DB_PASSWORD,
} = require("../config/config.base");
console.log(DB_DBS, DB_USERNAME, DB_PASSWORD);
const sequelize = new Sequelize(DB_DBS, DB_USERNAME, DB_PASSWORD, {
  host: DB_HOST,
  dialect: "mysql",
  define: {
    freezeTableName: true,
    underscored: true, // 驼峰 下划线
  },
  dialectOptions: { // 日期转换
    dateStrings: true,
    typeCast: true,
  },
});

module.exports = sequelize;

sequelize
  .authenticate()
  .then(() => {
    console.log("数据库连接成功");
  })
  .catch(() => {
    console.log("数据库连接失败");
  });
